<?php

declare(strict_types=1);

namespace App\Controller\Api;
use App\Controller\AbstractController;
use Hyperf\HttpServer\Annotation\AutoController;
use App\Model\BannerImage as ModelBannerImage;

/**
 * @AutoController(prefix="/api/bannerImage")
 */
class BannerImage extends AbstractController
{
    public function info() {
        $this->validate([
            'id' => 'required'
        ]);
        $model = ModelBannerImage::find($this->request->input('id'));
        return $this->success($model);
    }

    public function list() {
        $data = $this->request->all();
        $query = ModelBannerImage::query();

        if (!empty($data['banner_id'])) {
            $query = $query->where('banner_id', $data['banner_id']);
        }
        $query = $query->where('status', 1);

        $query = $query->orderBy('sorting', 'desc')
            ->orderBy('id', 'desc');
        $list = $query->get();
        return $this->success($list);
    }
}
